package com.customization.huangwm.workflowNodeAction;

import java.util.Timer;
import java.util.TimerTask;

import com.customization.huangwm.utils.LogTool;
import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;

import com.customization.huangwm.utils.DBTools;
import com.customization.huangwm.utils.DateTools;

import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @author Huangwm
 * @package com.customization.huangwm.workflowNodeAction
 * @description 霉候类流程归档时在转数据后更新流程创建日期和归档日期的时间差天数到个案中
 */
public class SetWorkflowEndTiemsToMH implements Action {
    private LogTool log = new LogTool("/log/huangwm/WfAction/SetWorkflowEndTiemsToMH", false);
    private DBTools dbTools = new DBTools();
    private DateTools dateTools = new DateTools();

    @Override
    public String execute(RequestInfo requestInfo) {
        final String date = dateTools.getCurrentDate();//当前日期
        final String time = dateTools.getCurrentTime();//当前时间
        final String times = dateTools.getCurrentTimes();//当前日期时间
        final String workflowCreateTime = dbTools.GetWorkflowCreatetime(requestInfo.getRequestid());//流程创建时间
        log.writeLog("候类流程归档时在转数据后更新流程创建日期和归档日期的时间差天数到个案中>>" + requestInfo.getRequestid());
        Timer timer = new Timer();//实例化Timer类
        timer.schedule(new TimerTask() {
            public void run() {
                RecordSet rs = new RecordSet();
                String sql = "select lzjlid from " + requestInfo.getRequestManager().getBillTableName() + " where requestid=" + requestInfo.getRequestid();
                log.writeLog("查询流转记录id：" + sql);
                rs.execute(sql);
                if (rs.next()) {
                    String lzjlid = rs.getString("lzjlid");
                    if (!"".equals(lzjlid) && lzjlid != null) {
                        RecordSet up = new RecordSet();
                        String upSql = "update uf_mh_trrecord set wgrq='" + date + "',gqday=" + dateTools.daysBetweenDateString(workflowCreateTime, date) + " where id=" + lzjlid;
                        log.writeLog("更新流转记录表：" + upSql);
                        boolean falg = up.execute(upSql);
                        log.writeLog("更新结果：" + falg);
                    }
                }
                this.cancel();
            }
        }, 2000);
        //return FAILURE_AND_CONTINUE;
        return SUCCESS;
    }

}
